//
//  CreateRoom.swift
//  
//
//  Created by Jiang Chencheng on 2024/9/3.
//

import Fluent

struct CreateRoom: AsyncMigration {
    func prepare(on database: Database) async throws {
        try await database.schema("room")
            .id()
            .field("name", .string, .required)
            .field("user_id_owner", .uuid, .required, .references("user", "id"))
            .field("user_id_partner", .uuid, .references("user", "id"))
            .field("pet_name", .string, .required)
            .field("pet_type", .string, .required)
            .field("star", .int64, .required)
            .field("hot", .int64, .required)
            .field("energy", .int64, .required)
            .field("created_at", .datetime)
            .field("updated_at", .datetime)
            .field("deleted_at", .datetime)
            .create()
    }

    func revert(on database: Database) async throws {
        try await database.schema("room").delete()
    }
}


struct UpdateRoomPlant: AsyncMigration {
    func prepare(on database: Database) async throws {
        try await database.schema("room")
            .field("plant_name", .string, .required)
            .field("plant_type", .string, .required)
            .field("plant_stage", .string, .required)
            .update()
    }

    func revert(on database: Database) async throws {
        try await database.schema("room")
            .deleteField("plant_type")
            .deleteField("plant_name")
            .deleteField("plant_stage")
            .update()
            
    }
}


struct UpdateRoomPetMood: AsyncMigration {
    func prepare(on database: Database) async throws {
        try await database.schema("room")
            .field("pet_mood", .string, .required)
            .update()
    }

    func revert(on database: Database) async throws {
        try await database.schema("room")
            .deleteField("pet_mood")
            .update()
            
    }
}
